<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" class="tl-dialog" width="1300px" @open="open" @close="close">
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
      <el-tabs v-model="activeTab" type="card">
        <el-tab-pane label="基础信息" name="basic">
          <el-row>
            <el-col :span="12">
              <el-form-item label="关联字段" :required="true" prop="key" :rules="rules.validateRequire">
                <el-input v-model="model.key" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="字段表达式" :required="false">
                <el-input v-model="model.expression" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="字段类型" :required="true" prop="datatype" :rules="rules.validateRequire">
                <el-select v-model="model.datatype" placeholder="请选择">
                  <el-option v-for="item in codeModel.datatypeList" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="字段值颜色" :required="false">
                <el-input v-model="model.keycolor" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="显示名称" :required="true" prop="title" :rules="rules.validateRequire">
                <el-input v-model="model.title" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="显示名称颜色" :required="false">
                <el-input v-model="model.titlecolor" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <!-- <el-form-item label="空值隐藏" :required="false">
            <el-input v-model="model.extendfield1" maxlength="85" style="width:100%"/>
          </el-form-item> -->
              <el-form-item label="空值隐藏" :required="false">
                <el-select v-model="model.extendfield1" placeholder="请选择">
                  <el-option v-for="item in codeModel.hiddenList" :key="item.code" :label="item.name" :value="item.code" />
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="排序码" :required="false">
                <el-input v-model="model.sortcode" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="字体样式" :required="false">
                <el-input v-model="model.extendfield2" placeholder="S（删除线）,U（下划线）,B（加粗）,I（斜体）,多个使用,隔开" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="是否可见" :required="false">
                <el-input v-model="model.extendfield10" placeholder="值为1时显示名称和跳转信息都不可见，否则如果mobileDataAction不为空优先显示跳转信息，用来传值使用" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="有效" :required="true">
                <el-select v-model="model.enabled" placeholder="请选择">
                  <el-option v-for="item in codeModel.enabledList" :key="item.code" :label="item.name" :value="parseInt(item.code)" />
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
        <el-tab-pane label="跳转信息" name="extend">
          <el-row>
            <el-col :span="24">
              <el-form-item label="titleKey" prop="titleKey" :rules="ruless.titleKey">
                <el-input v-model="myGson.titleKey" placeholder="跳转字段显示的key" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="titleValue" prop="titleValue" :required="false" :rules="ruless.titleValue">
                <el-input v-model="myGson.titleValue" placeholder="跳转字段显示的value" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="sourceType" :required="false">
                <el-input v-model="myGson.sourcetype" maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item label="mobileDataAction" :required="false">
                <el-input v-model="myGson.mobiledataaction" placeholder="loadmobileinfo接口地址类似 ltc/mlmowform/loadMobileLeadBackLinePageInfo " maxlength="85" style="width:100%" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-tab-pane>
      </el-tabs>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
import tlRefTreeModule from '@tapui/components/Tap/Ref/RefTree'
import { putAction, getAction, postAction } from '@tapui/utils/http'
export default {
  components: { tlRefTreeModule },
  mixins: [mixin_edit],
  data() {
    // <!--验证密码-->
    const validatetitleKey = (rule, value, callback) => {
      if (this.myGson.mobiledataaction !== '') {
        if (this.myGson.titleKey === '') {
          callback(new Error('不能为空'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    const validatetitleValue = (rule, value, callback) => {
      if (this.myGson.mobiledataaction !== '') {
        if (this.myGson.titleValue === '') {
          callback(new Error('不能为空'))
        } else {
          callback()
        }
      } else {
        callback()
      }
    }
    return {
      ruless: {
        titleKey: [{ trigger: 'blur', validator: validatetitleKey }],
        titleValue: [{ trigger: 'blur', validator: validatetitleValue }]
      },
      moduleTitle: 'APP页面元素',
      activeTab: 'basic',
      urlPrefix: '/app/appPageItems/',
      url: {},
      myGson: {
        sourcetype: '',
        mobiledataaction: '',
        titleKey: '',
        titleValue: ''
      }
    }
  },
  props: {
    datatypeList: {
      type: Array,
      default: function() {
        return []
      }
    },
    hiddenList: {
      type: Array,
      default: function() {
        return []
      }
    },
    enabledList: {
      type: Array,
      default: function() {
        return []
      }
    },
    pagetabid: {}
  },
  methods: {
    assignDefaultValue() {
      this.model.pagetabid = this.pagetabid
      // this.$refs.editForm.model.pageid = this.selectTreeNode.id
    },
    beforeSubmit() {
      this.model.extendfield3 = JSON.stringify(this.myGson)
      return true
      // extendfield3用来传递跳转信息
    },
    loaded() {
      this.myGson = {}
      if (this.model.extendfield3) {
        this.myGson = JSON.parse(this.model.extendfield3)
      }
    }
  }
}
</script>

<style lang="scss"></style>
